﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using WCS.Utils;
using WCS.Helpers;
using WCS.Entity;
using WcsTask;

namespace WCS.Controls.系统查询
{
    public partial class SendPLCCode : UIPage
    {
        public SendPLCCode()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 数据库连接对象
        /// </summary>
        static SqlSugarDapper _SqlSugarDapper = SqlSugarDapper.GetDbContext();

        private void AddTask_Load(object sender, EventArgs e)
        {
            TaskTableBind();
        }

        /// <summary>
        /// 成绩绑定
        /// </summary>
        private void TaskTableBind()
        {
            //获取当前页面的index
            int index = this.uiPagination1.ActivePage - 1;
            int pageIndex = this.uiPagination1.ActivePage;
            int size = this.uiPagination1.PageSize;
            int begin = (index * size) + 1;
            int end = (index + 1) * size;
            int count = 0;
            this.uiDataGridView1.DataSource = _SqlSugarDapper.DB.Queryable<WCS.Entity.WcsTaskConveyor>()
                .Where(w => w.Task_Type == "out")
                .OrderBy("CreateTime")//然后根据创建时间排序
                .ToPageList(pageIndex, size, ref count);
        }

        private void TaskTableBind1()
        {
            //获取当前页面的index
            int index = this.uiPagination1.ActivePage - 1;
            int pageIndex = this.uiPagination1.ActivePage;
            int size = this.uiPagination1.PageSize;
            int begin = (index * size) + 1;
            int end = (index + 1) * size;
            int count = 0;

            if (uiCheckBox1.Checked)
            {
                this.uiDataGridView1.DataSource = _SqlSugarDapper.DB.Queryable<WCS.Entity.WcsTaskConveyor>()
                .Where(w => w.TrayBar_Code == this.textcode.Text && w.Task_Type=="out")
                .ToPageList(pageIndex, size, ref count);
            }
            else
            {
                this.uiDataGridView1.DataSource = _SqlSugarDapper.DB.Queryable<WCS.Entity.WcsTaskConveyor>()
                .Where(w => w.Sub_TaskCode == this.textcode.Text && w.Task_Type == "out")
                .ToPageList(pageIndex, size, ref count);
            }
        }

        private void uiButton1_Click(object sender, EventArgs e)
        {
            textcode.Text = "";
            uiCheckBox1.Checked=false;
            TaskTableBind();
        }

        private void uiPagination1_PageChanged(object sender, object pagingSource, int pageIndex, int count)
        {
            TaskTableBind();
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uiButton2_Click(object sender, EventArgs e)
        {
            TaskTableBind1();
        }
    }
}
